# ! python3

import os
import re
from time import sleep

FX = {
    'UP': 'adb shell input tap 350 550',
    'DOWN': 'adb shell input tap 360 750',
    'LEFT': 'adb shell input tap 250 650',
    'RIGHT': 'adb shell input tap 450 650'
}


def input_adb():
    os.system('adb version')
    print('----------------------------')
    os.system('adb devices')
    print('----------------------------')
    out = os.popen('adb shell "dumpsys activity | grep "mFocusedActivity""').read()  # os.popen支持读取操作
    print(out)
    print('----------------------------')
    pattern = re.compile(r'[a-zA-Z0-9\.]+/[a-zA-Z0-9\.]+')
    out = os.popen("adb shell dumpsys window windows | findstr \/ | findstr name=").read()
    list = pattern.findall(out)
    component = list[0]  # 输出列表中的第一条字符串
    print(component)


def adb_get_png():
    now_path = __file__
    image_path = os.path.abspath(os.path.dirname(now_path) + os.path.sep + '..' + os.path.sep + 'image')
    os.system('adb shell /system/bin/screencap -p /sdcard/screenshot.png')
    os.system('adb pull /sdcard/screenshot.png %s/screenshot.png' % image_path)


def adb_get_move(fx):
    """
    方向
    :param fang_xiang:
    :return:
    """
    os.system(fx)


if __name__ == '__main__':
    # input_adb()
    # adb_get_png()
    i = 10
    while (i):
        adb_get_move(FX['UP'])
        sleep(1)
        adb_get_move(FX['DOWN'])
        sleep(1)
        adb_get_move(FX['LEFT'])
        sleep(1)
        adb_get_move(FX['RIGHT'])
        sleep(1)
        i -= 1
    print("完成！")
